package com.vodone.v1pin.detail.widgets
{
	import com.vodone.v1pin.component.linklabel.LinkLabel;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.net.drm.VoucherAccessInfo;
	
	import mx.managers.PopUpManager;
	
	public class ProductRecommendLabel extends LinkLabel
	{
		public function ProductRecommendLabel()
		{
			super();
			this.text = "商品推荐";
			addEventListener( MouseEvent.CLICK , clickHandler );
		}
		private var panel:ProductLinkPanel;
		
		private var _isVideo:Boolean = false;
		
		public function get isVideo():Boolean
		{
			return _isVideo;
		}

		public function set isVideo(value:Boolean):void
		{
			_isVideo = value;
		}

		private function clickHandler(e:MouseEvent):void
		{
			e.stopImmediatePropagation();
			openPopup();
		}
		private function openPopup():void
		{
			panel ||= new ProductLinkPanel();
			var localX:Number;
			var localY:Number;
			if(isVideo)
			{
				localX = -255;
				localY = 0;
				panel.styleName = "tuijianvideo";
			}
			else
			{
				localX = -45;
				localY = height + 5;
			}
			var globalPoint:Point = localToGlobal( new Point( localX , localY ) );
			panel.x = globalPoint.x;
			panel.y = globalPoint.y;
			PopUpManager.addPopUp( panel , this );
			
			if(!haveAdd)
			{
				stage.addEventListener(MouseEvent.CLICK , stageClickHandler );
				haveAdd = true;
			}
			
		}
		
		private var haveAdd:Boolean = false;
		
		private function stageClickHandler( e:MouseEvent ):void
		{
			if( panel != null && !panel.hitTestPoint( e.stageX , e.stageY ) )
			{
				panel.close();
			}
		}
	}
}